package com.easybbs.service.impl;

import com.easybbs.entity.po.MedicinePO;
import com.easybbs.entity.vo.web.ClassItemVO;
import com.easybbs.entity.vo.web.ClassVO;
import com.easybbs.mappers.LibraryMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
public class LibraryService {

    @Resource
    LibraryMapper libraryMapper;

    public List<ClassItemVO> getSidebar(){
        List<ClassVO> classVOS = libraryMapper.selectClasses();
        List<ClassItemVO> itemVOS = classVOS.stream().map(classVO -> {
            String[] childs = classVO.getClass2().split(" ");
            return new ClassItemVO(classVO.getClass1(), Arrays.asList(childs).stream().map(item -> new ClassItemVO(item)).collect(Collectors.toList()));
        }).collect(Collectors.toList());
        return  itemVOS;
    }

    public List<MedicinePO> getClassItemInfo(String itemName) {
        List<MedicinePO> medicinePOS = libraryMapper.selectClassItem(itemName);
        return medicinePOS;
    }
}
